package com.jie.web.controller;


import com.jie.dto.PrivateMessageDTO;
import com.jie.vo.ConditionVO;
import com.jie.vo.SingleChatMessageVO;
import com.jie.service.SingleChatService;
import com.jie.vo.CommonResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  私聊消息
 * </p>
 *
 * @author xiaojie
 * @since 2023-11-01
 */
@Api(tags = "私聊消息")
@RestController
@RequestMapping("/single-chat")
public class SingleChatController {
    @Autowired
    private SingleChatService singleChatService;
    @PostMapping("/send")
    @ApiOperation(value = "发送消息",notes="发送私聊消息")
    public CommonResponse<Long> sendMessage(@Valid @RequestBody SingleChatMessageVO vo){
        return CommonResponse.buildSuccess(singleChatService.sendMessage(vo));
    }
    @PostMapping("/load")
    @ApiOperation(value = "拉取消息",notes="拉取消息,一次最多拉取100条")
    public CommonResponse<Long> loadMessage(@RequestParam Long minId){
        return CommonResponse.buildSuccess(singleChatService.loadMessage(minId));
    }
    @PutMapping("/read")
    @ApiOperation(value = "消息已读",notes="将会话中接收的消息状态置为已读")
    public CommonResponse readedMessage(@RequestParam Long friendId){
        singleChatService.readMessage(friendId);
        return CommonResponse.buildSuccess();
    }

    @GetMapping("/history")
    @ApiOperation(value = "查询聊天记录",notes="查询聊天记录")
    public CommonResponse<List<PrivateMessageDTO>> recallMessage(@RequestParam Long friendId,
                                                                 ConditionVO conditionVO){
        return CommonResponse.buildSuccess(singleChatService.findHistoryMessage(friendId,conditionVO));
    }

}

